package com.design.graduation.asdemo.utils;

import android.content.Context;
import android.location.LocationManager;

import com.design.graduation.asdemo.model.InfoEntity;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.text.ParseException;
import java.util.List;

/**
 * Created by arvin on 2016/1/18 11:59.
 */
public class CurrentUtils {
    public static String getJsonFromObject(Object obj) {
        return new Gson().toJson(obj);
    }

    public static List<InfoEntity> getInfoListFromJson(String json) throws ParseException {
        return new Gson().fromJson(json, new TypeToken<List<InfoEntity>>() {
        }.getType());
    }

    public static InfoEntity getInfoEntityFromJson(String json) throws ParseException {
        return new Gson().fromJson(json, InfoEntity.class);
    }

    /**
     * @param context
     * @return true 表示开启
     */
    public static final boolean isOpenGPS(final Context context) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//        boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        return gps;
    }

}
